home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / MEMCPY.CX < prev    next >
Text File  |  1993-06-10  |  4KB  |  106 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 06-06-93 (18:59)             Number: 130
  4. From: TOM DONAHUE                  Refer#: NONE
  5.   To: JOHN CROUCH                   Recvd: NO  
  6. Subj: Help With .Asm 2 C             Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8.   John Crouch (1:282/115) writes to All:
  9.  
  10. > The following code is from the Programmer's Guide to EGA and VGA
  11. > Cards, by  Richard F. Ferraro.  I have had trouble getting this
  12. > code to work. Can someone supply the C code for this .asm code,
  13. > compatible with Borland 3.0?  Using inline assembly or whatever
  14. > is fine, I just need it working.
  15. >
  16. > ; Calling protocol:
  17. > ; RdFont(input_segment,input_offset,output,nchar,bpc);
  18. >
  19. > _RdFont proc far
  20. >     Prefix         ; Register saving macro I have NOT included.
  21. >
  22. >     mov ax,[bp+14]          ; do for "nchar" characters
  23. >     mul word ptr [bp+16]    ; " characters * bytes/character
  24. >     mov cx,ax               ; into counter for number of bytes
  25. >     mov ds,[bp+6]           ; point to source segment
  26. >     mov si,[bp+8]           ; point to source offset
  27. >     les di,[bp+10]          ; point to destination
  28. >     rep movsb
  29. >
  30. >     Postfix        ; Register restoring macro I have NOT included
  31. > _RdFont endp
  32.  
  33. OK, essentially this is a far memcpy so you have to be careful of
  34. pointer sizes.  Here are three ways to do it.
  35.  
  36. 1) In C with conditional compilation
  37.  
  38.     char output[FONTSIZE];
  39.  
  40. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  41.     /* near data, stack segment == data segment */
  42.     movedata(inseg, inofs, _DS, (unsigned)output, nchar*bpc);
  43. #else
  44.     memcpy((void *)output, (void *)MK_FP(inseg, inofs), nchar*bpc);
  45. #endif
  46.  
  47. 2) Use Ferraro's _RdFont as is but add "far" to the prootype
  48.    since it's hard wired for far code (the "far" after proc) and
  49.    far data pointers (les di). This works for all models.
  50.  
  51.    void far RdFont(unsigned int inseg, unsigned int inofs,
  52.                    char far *output, int nchar, int bpc);
  53.  
  54. 3) Take advantage of MASM/TASM support for C names and memory models.
  55.    This works in all models for MASM 5.0 and TASM 2.0 and later.
  56.    To use another model just change the "small" in the .model
  57.    directive to "large" etc.   For small models this will be a tad
  58.    more efficient than method 2) and IMO it's better anyway, but
  59.    I guess if you're writing for publication then you have to
  60.    consider other (or older) assemblers.
  61.  
  62. ; void  RdFont(unsigned int inseg, unsigned int inofs,
  63. ;              char *output, int nchar, int bpc);
  64.  
  65.         .model small, c
  66.         .code
  67.  
  68. RdFont  proc            ; near or far, depending on model
  69.  
  70.         arg  inseg:word, inofs:word, output:ptr, nchar:word, bpc:word
  71.         uses ds,si,di   ; save these registers at entry/exit
  72.  
  73.   if @DataSize EQ 0     ; tiny, small, medium model
  74.         push ds         ; assumes ds == ss
  75.         pop  es
  76.         mov  di,output
  77.   else                  ; compact, large, huge model
  78.         les  di,output  ; load far pointer
  79.   endif
  80.         mov  ax,nchar
  81.         mul  word ptr bpc
  82.         mov  ds,inseg
  83.         mov  si,inofs
  84.         rep  movsb
  85.         ret
  86. RdFont  endp
  87.  
  88.         ends
  89.         end
  90.  
  91. > A related question:  According to the book it is possible to have
  92. > 2 fonts loaded at one time, for a total of a possible 512 different
  93. > characters on the screen.  My need for the previous .asm code to be
  94. > translated is that I have the C code to make a text font italic, and
  95. > would like the ability to load 2 of the same font, and make 1 of
  96. > them italic.
  97.  
  98. Sorry I can't answer that, but I'd be interested in seeing the code.
  99. Is it generally available?
  100.  
  101. --- SuperBBS 1.17-2
  102.  * Origin: SuperBBS Support/Sales/Beta Avxia_bbs Tokyo Line 1 (6:730/9)
  103. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  104. SEEN-BY: 153/752 154/40 77 157/110 159/100 125 430 575 950 203/23 209/209
  105. SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  106.